home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Re: Unable to check callo
- Date: 7 Feb 1996 16:40:41 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4fakm9$24f@gail.ripco.com>
- NNTP-Posting-Host: foley.ripco.com
-
- ramli@sislnews.csc.ti.com (C. S. Ramalingam)
- in <4fadmp$t6g@osage.csc.ti.com> asks:
-
- >When would using calloc be more appropriate than using malloc ? Is it true
- >that the only use for calloc is in initializing integral values to zero ?
- >If so, why was a new function, which appears to have very limited used,
- >introduced in the first place ?
-
-
- It is extremely rare that I find it useful to use calloc(). If I needed
- to initialize a region of all bits zero (not necessarily the same as a
- floating-point zero or null pointer), I would use it. There are
- instances where this is useful, but functions such as memset(),
- memcpy(), memmove(), strcpy(), and strncpy() provide a more general way
- to initialize regions of memory without carrying the overhead of doing
- that initialization when allocating the space.
-
- At the time of K&R1 (1978), the "standard" library had calloc() but
- _not_ malloc(). malloc() is a stripped down version of calloc() rather
- than calloc() being an augmented malloc(). So calloc() exists in older
- C programs that would break if it were not available.
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-